//
//  ImagePageView.swift
//  SwiftUIDemo
//
//  Created by Kael on 2020/1/5.
//  Copyright © 2020 Kael. All rights reserved.
//

import SwiftUI

struct ImagePageView: View {
    
    @State var BGColor = Color.red
    @State var textColor = Color.white
    @State var isOn = true
        
        
        var body: some View {
            VStack {
                VStack {
                    Image("boy")
                        .resizable()
                        .frame(width: 100, height: 100, alignment: .center)
                        .background(Color.orange)
                        .clipShape(Circle())
                        .overlay(Circle().stroke(Color.white, lineWidth: 2))
        //                .shadow(color: .red, radius: 6, x: -3, y: 3)
                        .onAppear(perform: kaelImageAction)
                        .onTapGesture(perform: changeColor)
                        .padding(20)
                    
                    Text("鱼跃此时海，花开彼岸天")
                        .frame(width: 200, height: 40, alignment: .bottom)
                        .foregroundColor(self.textColor)
                    Toggle(isOn: $isOn) {
                        Text("State: \(self.isOn == true ? "开":"关")")
                            .foregroundColor(.white)
                    }.padding(20)
                    
                }
                .background(self.BGColor)
                
                VStack{
                    // ---------------
                    Image(systemName: "hand.thumbsup.fill")// 使用系统图片
                        .font(.largeTitle)
                    Image("boy")// 使用项目内的图片
                        .background(Color.orange)
                        .overlay(Text("Kaelinda").foregroundColor(Color.white))
                }
                .frame(maxWidth: .infinity)
                .background(self.BGColor)
            }
        }
        
        func kaelImageAction() -> Void {
            self.BGColor = Color.red
        }
        func changeColor() -> Void {
            if self.isOn {
                self.BGColor = Color.red
                self.textColor = Color.white
            }else{
                self.BGColor = Color.gray
                self.textColor = Color.black
            }
            
        }
}

struct ImagePageView_Previews: PreviewProvider {
    static var previews: some View {
        ImagePageView()
    }
}
